unit FecharComanda;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, Grids, DBGrids, DBTables, DB,
  DBClient;

type
  TFormFecharComanda = class(TForm)
    Bevel1: TBevel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Label1: TLabel;
    EditComanda: TEdit;
    DBGrid1: TDBGrid;
    Label12: TLabel;
    StaticTextTotal: TStaticText;
    cdsComanda: TClientDataSet;
    DataSource1: TDataSource;
    QueryComanda: TQuery;
    cdsComandacomanda: TIntegerField;
    cdsComandadata: TStringField;
    cdsComandavalor: TStringField;
    cdsComandaid_pedido: TIntegerField;
    procedure EditComandaKeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormFecharComanda: TFormFecharComanda;

implementation

uses Principal;

{$R *.dfm}

procedure TFormFecharComanda.EditComandaKeyPress(Sender: TObject;
  var Key: Char);
begin


if not(key in ['0'..'9',#8,#13]) then
      key := #0;

      
   if (key = #13) then
   begin

       QueryComanda.ParamByName('p_comanda').AsString := EditComanda.Text;
       QueryComanda.ParamByName('p_id_movimento').AsInteger := FormPrincipal.vIdmovimento;

       QueryComanda.Close;
       QueryComanda.open;

       cdsComanda.DisableControls;

       while not QueryComanda.Eof do
       begin

           cdsComanda.Append;
           cdsComandaid_pedido.AsInteger :=  QueryComanda.FieldByName('id').AsInteger;
           cdsComandacomanda.AsString :=  QueryComanda.FieldByName('nr_comanda').AsString;
           cdsComandavalor.AsString :=  QueryComanda.FieldByName('vl_pedido').AsString;
           cdsComandadata.AsString :=  QueryComanda.FieldByName('data').AsString;
           cdsComanda.Post;

           QueryComanda.Next;
           

       end;

       cdsComanda.EnableControls;



   end;
end;

procedure TFormFecharComanda.FormShow(Sender: TObject);
begin
    cdsComanda.CreateDataSet;
end;

end.
